home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Snippets / Platforms & Tools / MacApp / AEGestalt 1.0b3 / UAEDocument.cp < prev    next >
Encoding:
Text File  |  1991-12-11  |  8.3 KB  |  272 lines  |  [TEXT/MPS ]

  1. //     UAEDocument.cp 
  2. //     Copyright © 1991 by Apple Computer, Inc. All rights reserved.
  3. //    Kent Sandvik DTS
  4. //    This file contains the basic TAEDocument member functions
  5.  
  6.  
  7. // INCLUDES
  8.  
  9. #ifndef __AEDOCUMENT__
  10. #include "UAEDocument.h"                                        // class definitions
  11. #endif
  12.  
  13. //    CLASS METHODS 
  14.  
  15. //    Empty constructor - for avoiding ptabs in global data space
  16. #pragma segment ARes
  17. TAEDocument::TAEDocument() {}                    
  18.  
  19. //    Create TAEDocument
  20.  
  21. #pragma segment AInit
  22. pascal void TAEDocument::IAEDocument()
  23. {
  24.     inherited::IDocument();
  25.     
  26.     fAEGestaltAddress.descriptorType     = typeNull;            // initialize handle to AE
  27.     fAEGestaltAddress.dataHandle        = NULL;
  28.     fConfigurationInfo                    = NULL;
  29.     fOKNode                                = FALSE;
  30. }
  31.  
  32.  
  33. //    Create any needed TDocument Views
  34.  
  35. #pragma segment AOpen
  36. pascal void TAEDocument::DoMakeViews(Boolean /*forPrinting*/)
  37. {
  38.     TWindow*        aWindow = NULL;
  39.     FailInfo         fi;
  40.     
  41.     if(fi.Try()){
  42.         // create Main Information Window    
  43.         
  44.         aWindow = (TWindow *)gViewServer->NewTemplateWindow(kMainWindow, this);
  45.     
  46.         fInfoField     = (TStaticText *)aWindow->FindSubView('info');
  47.         fLabelView     = (TLabelView *)aWindow->FindSubView('VIW1);
  48.         fInfoView    = (TInformationView *)aWindow->FindSubView('VIW2');
  49.  
  50.  
  51. //    Add Adorners to various views - yes this would be far better to do
  52. //    from the resource file itself, but as long as there's no ViewEdit 3.0
  53. //    which handles the new format, I'm hesitant to hack in by hand these
  54. //    values, because it's a tidy exersize.
  55.  
  56.         // add window adorners, fill gray background
  57.         
  58.         aWindow->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion), 
  59.                                             kAdornBefore, kRedraw);
  60.                                             
  61.         // add view adorners, frame second view
  62.  
  63.         fInfoView->AddAdorner(NewStdAdorner('fram', "", 'fram', kFreeOnDeletion),
  64.                                             kDrawView, kRedraw);
  65.         fInfoView->AddAdorner(NewStdAdorner('eras', "", 'eras', kFreeOnDeletion),
  66.                                             kDrawView, kRedraw);
  67.         
  68.         
  69.         
  70.         // add static text adorner, erase background
  71.         
  72.         fInfoField->AddAdorner(NewStdAdorner('eras', "", 'eras', kFreeOnDeletion),
  73.                                                 kDrawView, kRedraw);
  74.         fi.Success();
  75.     }
  76.     else
  77.         fi.ReSignal();
  78. }
  79.  
  80.  
  81. //    Handle Events passed to TDocument, like the find button event
  82.  
  83. #pragma segment AMain
  84. pascal void TAEDocument::DoEvent(EventNumber eventNumber, TEventHandler* source,
  85.                                     TEvent* event)
  86. {
  87.     if(eventNumber == mButtonHit){            // were any of the buttons pressed?
  88.         if(source->fIdentifier == 'find'){    // find button?    
  89.         // post a menu command which translates to the Find… menu entry    
  90.             this->HandleMenuCommand(cFindAEGestalt);
  91.         }
  92.  
  93.         else if(source->fIdentifier == 'repo'){    // report button?
  94.             if(fOKNode)                            // we have valid node?
  95.             // post a menu command which translates to the Report… menu entry    
  96.                 this->HandleMenuCommand(cCreateReport);
  97.         }
  98.     }
  99.     else
  100.         inherited::DoEvent(eventNumber,source,event);
  101. }
  102.  
  103.  
  104. //    Free any resources attached to the TDocument, take also care of AE resources
  105.  
  106. #pragma segment AClose
  107. pascal void TAEDocument::Free()
  108. {
  109.     AEAddressDesc aDesc = fAEGestaltAddress;
  110.     AEDisposeDesc(aDesc);                    // dispose the descriptor!
  111.  
  112.     inherited::Free();
  113. }
  114.  
  115.  
  116. //    Setup menus when TDocument is created
  117.  
  118. #pragma segment ARes
  119. pascal void TAEDocument::DoSetupMenus()
  120. {
  121.     inherited::DoSetupMenus();
  122.     Enable(cFindAEGestalt, TRUE);
  123.     Enable(cCreateReport, fAEGestaltAddress.dataHandle != NULL);
  124. }
  125.  
  126.  
  127. //    Handle menu commands assigned to the TDocument controlled menus
  128.  
  129. #pragma segment ASelCommand
  130. pascal void TAEDocument::DoMenuCommand(CommandNumber theNumber)
  131. {
  132.     TCommand*            cmdToPost     = NULL;
  133.     TAEClientCommand*    AEcmd        = NULL;
  134.     TLookupCommand*        aLookup        = NULL;
  135.     
  136.     
  137.     switch(theNumber){
  138.         case cFindAEGestalt:
  139.             aLookup = new TLookupCommand;
  140.             aLookup->ILookupCommand(cFindAEGestalt, this);
  141.             cmdToPost = aLookup;
  142.             fInfoField->SetText("Look for node to examine...", TRUE);
  143.             break;
  144.  
  145.         case cCreateReport:
  146.             AEcmd = new TAEClientCommand;
  147.             AEcmd->IAEClientCommand(cCreateReport, this, kAEGetConfig);
  148.             cmdToPost = AEcmd;
  149.             fInfoField->SetText("Report node information...", TRUE);
  150.             break;
  151.             
  152.         default:
  153.             inherited::DoMenuCommand(theNumber);
  154.     }
  155.     if(cmdToPost != NULL) this->PostAnEvent(cmdToPost);
  156. }
  157.  
  158.  
  159. //    Return the AppleEvents address stored in TAEDocument
  160.  
  161. #pragma segment ARes
  162. pascal void TAEDocument::GetAEGestaltAddress(AEAddressDesc& theAddress)
  163. {
  164.     theAddress = fAEGestaltAddress;
  165. }
  166.  
  167. //    Read the Configuration information
  168. #pragma segment Main
  169. pascal void TAEDocument::ReadConfiguration(Configuration* theConfig)
  170. {
  171.     BlockMove(&theConfig, &fConfigurationInfo, sizeof(theConfig));
  172. }
  173.  
  174.  
  175. //    Process the information we got from the AE for the View class for
  176. //    later display
  177.  
  178. #pragma segment Main
  179. pascal void TAEDocument::ProcessAEInformation()
  180. {
  181.     switch(fConfigurationInfo->machineType){        // Label1 - Machine Type
  182.         case 1: fInfoView->fLabel1 = "Classic";         break;
  183.         case 2: fInfoView->fLabel1 = "MacXL";             break;
  184.         case 3: fInfoView->fLabel1 = "Mac512KE";         break;
  185.         case 4: fInfoView->fLabel1 = "Mac Plus";        break;
  186.         case 5: fInfoView->fLabel1 = "MacSE";            break;
  187.         case 6: fInfoView->fLabel1 = "MacII";            break;
  188.         case 7: fInfoView->fLabel1 = "MacIIx";            break;
  189.         case 8: fInfoView->fLabel1 = "MacIIcx";            break;
  190.         case 9: fInfoView->fLabel1 = "MacSe030";        break;
  191.         case 10:fInfoView->fLabel1 = "Portable";        break;
  192.         case 11:fInfoView->fLabel1 = "MacIIci";            break;
  193.         case 13:fInfoView->fLabel1 = "MacIIfx";            break;
  194.         case 17:fInfoView->fLabel1 = "Mac Classic";        break;
  195.         case 18:fInfoView->fLabel1 = "MacIIsi";            break;
  196.         case 19:fInfoView->fLabel1 = "MacLC";            break;
  197.         case 20:fInfoView->fLabel1 = "Quadra 900";        break;
  198.         case 21:fInfoView->fLabel1 = "PowerBook 140";    break;
  199.         case 22:fInfoView->fLabel1 = "Quadra 700";        break;
  200.         case 23:fInfoView->fLabel1 = "Classic II";        break;
  201.         case 24:fInfoView->fLabel1 = "PowerBook 100";    break;
  202.         case 25:fInfoView->fLabel1 = "PowerBook 140";    break;
  203.         default:fInfoView->fLabel1 = "Unknown type";    break;
  204.     }
  205.     
  206.     if(fConfigurationInfo->systemVersion == 0x700)            // Label2 - System Version
  207.         fInfoView->fLabel2 = "System 7.0";
  208.     else if(fConfigurationInfo->systemVersion == 0x701)
  209.         fInfoView->fLabel2 = "System 7.0.1";
  210.     else if(fConfigurationInfo->systemVersion == 0x602)
  211.         fInfoView->fLabel2 = "System 6.0.2";
  212.     else if(fConfigurationInfo->systemVersion == 0x603)
  213.         fInfoView->fLabel2 = "System 6.0.3";
  214.     else if(fConfigurationInfo->systemVersion == 0x604)
  215.         fInfoView->fLabel2 = "System 6.0.4";
  216.     else if(fConfigurationInfo->systemVersion == 0x605)
  217.         fInfoView->fLabel2 = "System 6.0.5";
  218.     else if(fConfigurationInfo->systemVersion == 0x607)
  219.         fInfoView->fLabel2 = "System 6.0.7";
  220.     else if(fConfigurationInfo->systemVersion < 0x600)
  221.         fInfoView->fLabel2 = "Pre 6.0.x System";
  222.     else if(fConfigurationInfo->systemVersion > 0x701)
  223.         fInfoView->fLabel2 = "Post 7.0.1 System";
  224.     
  225.     switch(fConfigurationInfo->processor){            // Label3 - Processor Type
  226.         case 1: fInfoView->fLabel3 = "68000";         break;
  227.         case 2: fInfoView->fLabel3 = "68010";         break;
  228.         case 3: fInfoView->fLabel3 = "68020";         break;
  229.         case 4: fInfoView->fLabel3 = "68030";         break;
  230.         case 5: fInfoView->fLabel3 = "68040";         break;
  231.         default:fInfoView->fLabel3 = "Unknown CPU"; break;
  232.     }                
  233.                 
  234.     if(fConfigurationInfo->hasFPU)                    // Label4 - Has FPU?
  235.         fInfoView->fLabel4 = "TRUE"; 
  236.     else fInfoView->fLabel4 = "FALSE";
  237.     
  238.     if(fConfigurationInfo->hasColorQD)                // Label5 - Has Color QD?
  239.         fInfoView->fLabel5 = "TRUE"; 
  240.     else fInfoView->fLabel5 = "FALSE";
  241.     
  242.     if(fConfigurationInfo->has32BitQD)                // Label6 - Has 32-bit QD?
  243.         fInfoView->fLabel6 = "TRUE";
  244.     else fInfoView->fLabel6 = "FALSE";
  245.     
  246.     if(fConfigurationInfo->hasSCSI)                    // Label7 - Has SCSI?
  247.         fInfoView->fLabel7 = "TRUE";
  248.     else fInfoView->fLabel7 = "FALSE";
  249.  
  250.     if(fConfigurationInfo->hasAppleEventMgr)        // Label8 - Has AppleEvent Mgr?
  251.         fInfoView->fLabel8 = "TRUE";
  252.     else fInfoView->fLabel8 = "FALSE";
  253.     
  254.     if(fConfigurationInfo->hasEditionMgr)            // Label9 - Has Edition Mgr?
  255.         fInfoView->fLabel9 = "TRUE";
  256.     else fInfoView->fLabel9 = "FALSE";
  257.     
  258.     if(fConfigurationInfo->hasAUX)                    // Label10 - Is A/UX System?
  259.         fInfoView->fLabel10 = "TRUE";
  260.     else fInfoView->fLabel10 = "FALSE";
  261.     
  262.     if(fConfigurationInfo->hasTrueType)                // Label11 - Has TrueType?
  263.         fInfoView->fLabel11 = "TRUE";
  264.     else fInfoView->fLabel11 = "FALSE";
  265.     
  266.     CStr255 tempString;                                // Label12 - AppleTalk version
  267.     NumToString(long(fConfigurationInfo->atDrvrVersNum),tempString);
  268.     fInfoView->fLabel12 = tempString;
  269.     
  270.     fInfoView->fHasGestaltInfo = TRUE;                // report for view to draw
  271.     fInfoView->ForceRedraw();                        // redraw the view
  272. }